package cn.lili.modules.promotion.serviceimpl;

import cn.lili.common.vo.PageVO;
import cn.lili.modules.promotion.entity.dos.AdvertisingSpace;
import cn.lili.modules.promotion.mapper.AdvertisingSpaceMapper;
import cn.lili.modules.promotion.service.AdvertisingSpaceSerivce;
import cn.lili.mybatis.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @author:xiangqian
 * @date: 2024/4/17 9:18
 */
@Service
@Slf4j
public class AdvertisingSpaceSerivceImpl extends ServiceImpl<AdvertisingSpaceMapper, AdvertisingSpace> implements AdvertisingSpaceSerivce {

    /**
     * 分页查询贡献值明细
     *
     * @param advertisingSpace 查询条件{@link AdvertisingSpace}
     * @param page             分页条件{@link PageVO}
     * @return 分页返回结果
     */
    @Override
    public Page<AdvertisingSpace> pageSpace(AdvertisingSpace advertisingSpace, PageVO page) {
        Page<AdvertisingSpace> advertisingSpacePage = this.baseMapper.selectPage(PageUtil.initPage(page), new LambdaQueryWrapper<>());
        return advertisingSpacePage;
    }

    /**
     * 启用/关闭广告位
     *
     * @param advertisingSpace
     * @return
     */
    @Override
    public Boolean updateStatus(AdvertisingSpace advertisingSpace) {
        //1.判空
        Assert.notNull(advertisingSpace.getId(), "广告位ID不能为空");
        Assert.notNull(advertisingSpace.getStatus(), "广告位状态不能为空");

        //2.查询广告位
        AdvertisingSpace dbAdvertisingSpace = this.baseMapper.selectById(advertisingSpace.getId());
        Assert.notNull(dbAdvertisingSpace, "广告位不存在");

        //3.更新广告位
        dbAdvertisingSpace.setStatus(advertisingSpace.getStatus());
        return this.baseMapper.updateById(dbAdvertisingSpace) > 0 ? true : false;
    }
}
